<?php
/**
 * ============================================================================
 * @package Forum
 * @author Andy
 * @version 11:12
 * @link https://sjdphp.com
 * ----------------------------------------------------------------------------
 */

namespace app\admin\business;


use app\common\server\Json;

class InvBus extends BusBase
{

    public static function insertOrUpdateAndDel($param,$type = 1){
        $model = self::getModelExample();


        ## 判断是否存在上传后的数据
        if(isset($param["file"])){
            unset($param["file"]);
        }

        ## 判断操作类型
        $str = '';
        switch ($type){
            case 1:
                $res = $model::create($param);
                event("addInvByPlate",$param["plate_id"]);
                $str = '新增';
                break;
            case 2:
                $res = $model::update($param);
                $str = '更新';
                break;
            default:
                $res = $model::update($param);
                event("delInvByPlate",$param["inv_id"]);
                $str = '删除';
                break;
        }

        if($res){
            return Json::success($str . '成功');
        }else{
            return Json::error($str . "失败");
        }

    }
}